import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { Consts } from 'src/app/consts/consts';
import { DictDto } from 'src/app/models/sys/dict.dto';
import { GroupTypeDto } from 'src/app/models/sys/group-type.dto';
import { ApiService } from 'src/app/services/api.service';

@Component({
  selector: 'app-group-type-detail',
  templateUrl: './group-type-detail.component.html',
  styleUrl: './group-type-detail.component.less'
})
export class GroupTypeDetailComponent implements OnInit {
  @Input() groupTypeSubject = new BehaviorSubject<DictDto>(new DictDto());
  @Output() detailEvent = new EventEmitter<boolean>();

  groupType?: GroupTypeDto;

  constructor(private _api: ApiService) {

  }

  ngOnInit(): void {
    this.groupTypeSubject.subscribe((type) => {
      this._api.getGroupTypeDetail(type.id!).subscribe((resp) => {
        if (resp.code == Consts.RESP_OK && resp.data) {
          this.groupType = resp.data;
        }
      });
    });
  }

  onClose(event: UIEvent) {
    event.preventDefault();

    this.detailEvent.emit(true);
  }
}
